<?php

/*

  Action	$5

  Draw until you have 7 cards in hand.
  You may set aside any Action cards drawn this way, as you draw them; discard the set aside cards after you finish drawing.

 */

class Library extends Card implements iAction, iKingdom, iBasic {

    public function __construct() {
        parent::__construct("Library", 5);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }

    public function getDescription() {
        return array(
            "Draw until you have 7 cards in hand.  You may set aside any Action cards drawn this way, as you draw them; discard the set aside cards after you finish drawing.");
    }
    
    public function play(Game $game, $isRealCard) {

        $discardCards = array();
        while ($game->getPlayHandSize() < 7) {
            //only looking on the top card
            $card = $game->peekCardFromDrawDeck();
            if ($card == null) {
                break;
            }

             ScreenDisplay::addScreenMessage($game, true, "got " . nicePrint($card), "draws 1 card");
            if ($card instanceof iAction) {
                //if the card is an action, we send the user an option to take it or not

                $options = array(new Option(1, "Yes"), new Option(2, "No"));
                $output = MySocket::GetUserReply($game, Input_ChooseOne, $options, 1, 1, 'null', "Put " . $card->getValue() . " in Hand?");
                if ($output[0] == "Yes") {
                    $game->drawCards(1);
                     ScreenDisplay::addScreenMessage($game, false, " and put it in hand", " and puts it in hand");
                } else {
                    $card = $game->removeCardFromDrawDeck();
                     ScreenDisplay::addScreenMessage($game, false, " and put it aside", " and puts aside " . nicePrint($card));
                    $discardCards[] = ($card);
                }
            } else {
                //otherwise we draw it
                $game->drawCards(1);
                 ScreenDisplay::addScreenMessage($game, false, " and put it in hand", " and puts it in hand");
            }
        }

        $game->discardTempDiscardCards($discardCards);
        
        $game->cardActionFinished();
        return true;
    }

}

?>